<template>
	<div v-show="hndyHome">
		<van-nav-bar fixed title="二昆虫零售系统" @click-right="showMessage">
			<template #right>
				<a href="/m/home/sitemessage">
					<img class="right-msg" src="@/assets/hndy/message.png" alt="消息">
				</a>
			</template>
		</van-nav-bar>
		<div class="has-top">
			<!-- 公告 -->
			<div v-show="showWelcome" class="color-primary  flex-s-c pd-16" style="background:#F9EACD;">
				<svg-icon icon-class="trumpet" class="fs-40 mr-10 color-primary flex-s-0" />
				<p class="flex-g-1">欢迎回来，尊敬的{{ storeInfo.DealerGradesName }}【{{ storeInfo.ShowName }}】</p>
				<svg-icon icon-class="close-1" class="fs-32 color-primary  flex-s-0" @goPage="showWelcome = false" />
			</div>
			<!-- 主图 -->
			<van-swipe class="my-swipe shop-bg-box" :autoplay="3000" indicator-color="white">
				<van-swipe-item>
					<!--<img src="@/assets/hndy/h1.png" alt="主图">-->
					<img src="@/assets/hndy/h1.jpg" alt="主图">
				</van-swipe-item>
				<van-swipe-item>
					<!--<img src="@/assets/hndy/h2.png" alt="主图">-->
					<img src="@/assets/hndy/h2.jpg" alt="主图">
				</van-swipe-item>
				<van-swipe-item>
					<!--<img src="@/assets/hndy/h3.png" alt="主图">-->
					<img src="@/assets/hndy/h3.jpg" alt="主图">
				</van-swipe-item>
			</van-swipe>
			<!-- <img src="@/assets/hndy/homeBanner.png" alt="主图"> -->
			<!-- 功能区 -->
			<div class="btnList">
				<div v-for="(item, index) in btnList" :key="index" class="item" @click="gopage(item)">
					<svg-icon :icon-class="item.icon" class="fs-96 color-primary  flex-s-0" @goPage="gopage(item)" />
					<p class="fs-28 pt-16">{{ item.text }}</p>
				</div>
			</div>
			<!-- 链接区 -->
			<div class="linkList">
				<div v-for="(item, index) in linkList" :key="index" class="item bg-primary" @click="goOutLink(item.link)">
					<img :src="item.icon" :alt="item.title">
					<div class="">
						<p class="title text-show-line-1">{{ item.title }}</p>
						<p class="text text-show-line-1">{{ item.text }}</p>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import { GetUserStore } from 'api/store'
import { Toast } from 'vant'
export default {
	components: {

	},

	data() {
		return {
			hndyHome:false,
			storeInfo: {},
			showWelcome: false,
			btnList: [
				{
					icon: 'dy-icon-1',
					text: '我要订货',
					link: '/m',
					isNew: false
				},
				{
					icon: 'dy-icon-2',
					text: '我的订单',
					link: '/m/user/order',
					isNew: false
				},
				{
					icon: 'dy-icon-3',
					text: '我的账户',
					link: '/user/account',
					isNew: true
				},
				{
					icon: 'dy-icon-4',
					text: '邀请代理',
					link: '/agentInvite',
					isNew: true
				},
				{
					icon: 'dy-icon-5',
					text: '管理代理',
					link: '/agentManage',
					isNew: true
				},
				{
					icon: 'dy-icon-6',
					text: '个人中心',
					link: '/user/center',
					isNew: true
				}
			],
			linkList: [
				{
					icon: require('@/assets/hndy/link-icon-1.png'),
					title: '品牌介绍',
					text: '二昆虫品牌介绍',
					link: 'http://www.ekunchong.com'
				},
				{
					icon: require('@/assets/hndy/link-icon-2.png'),
					title: '二昆虫商学院',
					text: '二昆虫最新资讯',
					link: ''
				},
				{
					icon: require('@/assets/hndy/link-icon-3.png'),
					title: '二昆虫实体店',
					text: '效果图/实拍图',
					link: 'https://pan.baidu.com/s/1d_jjUD1V7DbrLw5wT1DCxQ'
				},
				{
					icon: require('@/assets/hndy/link-icon-4.png'),
					title: '二昆虫素材',
					text: '素材即时查询',
					link: 'https://pan.baidu.com/s/1aVfExvAdM-SWArXSoBlU-Q'
				}

			]
		}
	},
	computed: {

	},
	created() {
		var businessId = this.$webInfo.BusinessId;
		if(businessId=='4843'){
			this.hndyHome = true;
			this.GetUserStore()
		}else{
			this.$toast({
				message: '没有权限访问该页面',
				icon: 'warn-o',
				duration: 3000
			})
			setTimeout(e => {
				window.location.href = '/m/user'
			},3000)
		}

	},
	activated() { },
	methods: {
		showMessage() {
			console.log('显示消息')
		},
		goOutLink(link) {
			if (link) {
				window.location.href = link
			}
		},
		gopage(item) {
			console.log(123123)
			var status = localStorage.getItem('homestatus')
			console.log(status)
			if (status != 1) {
				this.$toast('没有访问权限')
				return false
			}
			// if (item.text == '我的账户' && this.storeInfo.DealerGradesName != '经销商') {
			//   this.$toast('没有访问权限')
			//   return false
			// }
			if (item.isNew) {
				this.$router.push({
					path: item.link
				})
			} else {
				window.location.href = item.link
			}
		},
		GetUserStore() {
			GetUserStore().then(res => {
				console.log(res)
				if (res.Data && res.Data.Status) {
					localStorage.setItem('homestatus', res.Data.Status)
				} else {
					localStorage.setItem('homestatus', 99)
				}
				if (res && res.Data) {
					if (res.Data.Status != 1) {
						window.location.href = '/m/user'
					}
					this.storeInfo = res.Data
					if (this.storeInfo.V_RealName) {
						this.storeInfo.ShowName = this.storeInfo.V_RealName
					} else if (this.storeInfo.V_NickName) {
						this.storeInfo.ShowName = this.storeInfo.V_NickName
					} else if (this.storeInfo.ContactName) {
						this.storeInfo.ShowName = this.storeInfo.ContactName
					} else if (this.storeInfo.Name) {
						this.storeInfo.ShowName = this.storeInfo.Name
					}
					this.showWelcome = true
					console.log(res.State)

				} else if (res.State != 1) {
					this.$toast.clear()
					Toast.clear()
					if (res.Msg == '微商信息不存在') {
						this.$toast({
							message: '请扫邀请码进行加盟',
							icon: 'warn-o',
							duration: 2000
						})
					} else {
						this.$toast(res.Msg)
					}
					// setTimeout(e => {
					// 	window.location.href = '/m'
					// },3000)
				}
			})
		}
	}
}
</script>
<style lang="scss" scoped>
.right-msg {
	width: 50px;
	height: 48px;
}

.btnList {
	margin: 34px 32px 14px;
	display: flex;
	flex-wrap: wrap;

	.item {
		width: calc(33% - 14px);
		text-align: center;
		background: #fff;
		border-radius: 24px;
		padding: 28px 10px 36px;
		margin-bottom: 20px;
		margin-right: 20px;

		&:nth-child(3n) {
			margin-right: 0;
		}
	}
}

.linkList {
	margin: 14px 32px;
	display: flex;
	flex-wrap: wrap;

	.item {
		width: calc(50% - 10px);
		// text-align: center;
		border-radius: 16px;
		padding: 28px 10px 36px;
		margin-bottom: 20px;
		margin-right: 20px;
		color: #fff;
		display: flex;
		align-items: center;

		&:nth-child(2n) {
			margin-right: 0;
		}

		img {
			width: 96px;
			height: 96px;
			margin-right: 16px;
		}

		.title {
			font-size: 28px;
			font-weight: 500;
		}

		.text {
			font-size: 24px;
			margin-top: 8px;
		}
	}
}
</style>
